<!--
 * @Author: dongdong.wu
 * @Date: 2020-08-07 09:13:13
 * @Description: card基础组件
-->
<template>
  <el-card ref="card">
    <div v-if="title || btnTitle" slot="header" class="card-header-between">
      <div class="title-component">
        <span class="card-title"
          >{{ title
          }}<span v-if="subTitle" class="card-subt-title"
            >（{{ subTitle }}）</span
          ></span
        >
        <slot name="component" />
      </div>
      <div class="card-header_btn">
        <el-button
          v-if="btnTitle && $hasPerm(perm)"
          :icon="btnIcon"
          type="text"
          @click="handleClick"
          >{{ btnTitle }}</el-button
        >
        <slot name="btns" />
      </div>
    </div>
    <slot />
  </el-card>
</template>

<script>
export default {
  name: "WeCard",
  props: {
    title: {
      // card 标题
      type: String,
      default: ""
    },
    subTitle: String, // 副标题
    btnIcon: {
      // 文字（图标）类型icon
      type: String,
      default: ""
    },
    btnTitle: {
      // 按钮名称（后期可扩展增加icon）
      type: String,
      default: ""
    },
    // 默认权限标识
    perm: String
  },
  methods: {
    handleClick() {
      this.$emit("click");
    }
  }
};
</script>

<style lang="scss" scoped>
.card-header-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  .title-component {
    display: flex;
    align-items: center;
  }
  .card-title {
    margin-right: 10px;
    font-size: 14px;
    font-weight: 700;
    .card-subt-title {
      font-size: 13px;
      font-weight: 400;
      color: var(--component-color);
    }
  }
}
::v-deep .el-button + .el-button {
  margin-left: 0px;
  i {
    font-size: 16px;
  }
}
::v-deep {
  .el-card__header {
    padding: 10px 20px;
  }
  .el-card__body {
    padding: 5px !important;
  }
}
</style>
